﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace WpfControlDemo.依赖属性
{
    //1.依赖属性需要继承自DependencyObject
    public class UserInfo : DependencyObject
    {
        //普通属性
        public int UserId { get; set; }
        //2.声明依赖属性
        public static readonly DependencyProperty UserNameProperty;
        static UserInfo()
        {
            //3.注册依赖属性
            // 参数1：设置依赖属性名称 参数2：设置依赖属性值类型 参数3：设置依赖属性所属类型 参数4：设置依赖属性默认值
            UserNameProperty = DependencyProperty.Register("UserName", typeof(string), typeof(UserInfo), new PropertyMetadata(string.Empty));
        }

        //4.属性包装，提供属性读写操作
        public string UserName
        {
            get { return (string)GetValue(UserNameProperty); }
            set { SetValue(UserNameProperty, value); }
        }
    }
}
